/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mediana;

import java.util.ArrayList;
import java.util.concurrent.Semaphore;

/**
 *
 * @author mateusz.ledzewicz
 */
public class Bufor {
     
    public static ArrayList<Range> bufor;
    public static Semaphore sem = new Semaphore(1);
    public static void init(Table table){
        bufor = new ArrayList();
        bufor.add(new Range(0, table.getSize()-1));
    }
    
    public static Range popRange() throws InterruptedException{
        Range range;
        sem.acquire();
        if(Bufor.bufor.isEmpty())
            range = null;
        else 
            range = bufor.remove(Bufor.bufor.size()-1);
        sem.release();
        return range;
    }
    public static void pushRange(Range range){
        Bufor.bufor.add(range);
    }
    
    
    
}
